﻿using Delphi.Apoll.Eod;
using Delphi.Apoll.Pilot;
using Delphi.Apoll.Updater;
using Delphi.Isis.Yahoo;
using Delphi.Mimir.Config;
using Delphi.Mimir.Data.Entities.Final;
using Delphi.Mimir.Migrations;
using Delphi.Mimir.Wrapper;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace Delphi.Apoll {
    class Program {
        static void Main(string[] args) {

            //FredApi fred = FredApi.GetInstance(ParameterWrapper.GetParameter("FRD", "Mimir", "Login", "WebService").OutParm1);
            //fred.Test();

            // 1587783
            // ManagedProductTrade.CreateManagedProduct(true, 100000, "Rebalancing Eq/FI 50 USD Benchmark", "REB50X", null);
            //ManagedProductTrade.SimulatedTrade(1587784, 842, 0, 25000, new DateTime(2016, 1, 1));
            //ManagedProductTrade.SimulatedTrade(1587784, 1910, 0, 50000, new DateTime(2016, 1, 1));
            //ManagedProductTrade.SimulatedTrade(1587784, 1003, 0, 25000, new DateTime(2016, 1, 1));

            //ManagedProductTrade.CalculateQuotes("REB50X");
            //List<int> symbols = new List<int>();
            //symbols.Add(1910);
            //ManagedProductTrade.Rebalance("REB50", new DateTime(2016, 1, 1), DateTime.Now.Date, symbols, 0.5, 0.05);

            EodFile ef = new EodFile();
            ef.Import(@"C:\Users\Thomas\Documents\EODData");

            using(YahooUpdater yup = new YahooUpdater()) {
                yup.LoadFullHistoryNewSymbols();

            }

            using (EodUpdater up = new EodUpdater()) {
                up.UpdateAll();
                //up.Quotes("NSE", new DateTime(2016, 5, 10), new DateTime(2016, 5, 13), "D");
                //up.Symbols("MSE", 101);
                
                
            }

            
            /*
            Exchange exc = ExchangeWrapper.GetExchange("NASDAQ");
            ICollection<Symbol> syms = SymbolWrapper.GetYahooSymbols(exc, true);
            foreach(Symbol sym in syms) {
                Console.WriteLine(sym.ShortLable);

                
                List<YahooIncomeStatement> yis = YahooScraper.GetIncomeStatement(sym.YahooCode, false);
                if(yis == null) {
                    continue;
                }
                FinancialStatementWrapper.AddStatement(yis);
                yis = YahooScraper.GetIncomeStatement(sym.YahooCode, true);
                FinancialStatementWrapper.AddStatement(yis);
                
                List<YahooBalanceSheet> ybs = YahooScraper.GetBalanceSheet(sym.YahooCode, false);
                FinancialStatementWrapper.AddStatement(ybs);
                ybs = YahooScraper.GetBalanceSheet(sym.YahooCode, true);
                FinancialStatementWrapper.AddStatement(ybs);

                List < YahooCashFlow > ycf = YahooScraper.GetCashFlow(sym.YahooCode, false);
                FinancialStatementWrapper.AddStatement(ycf);
                ycf = YahooScraper.GetCashFlow(sym.YahooCode, true);
                FinancialStatementWrapper.AddStatement(ycf);
                

            //List<YahooAnalystEstimates> yae = YahooScraper.GetAnalystEstimate(sym.YahooCode);
            //AnalystEstimateWrapper.AddEstimates(yae);
            }



    */
            
            //Console.ReadKey();
        }
    }
}

